'use strict';
// 基类
const Service = require('egg').Service;

class BaseService extends Service {
  // 成功时调用此接口
  success (data) {
    return {
      errno: this.config.result.SUCCESS.errno,
      errmsg: '成功',
      data: data || ''
    }
  }
  fail (resultEnum, data, message) {
    let obj
    if (typeof resultEnum == 'object') {
      obj = {
        errno: resultEnum.errno,
        errmsg: message !== undefined && message !== '' ? message : resultEnum.errmsg,
        data: data || ''
      }
    } else {
      obj = {
        errno: resultEnum,
        errmsg: message,
        data: data
      }
    }
    return obj
  }
}

module.exports = BaseService;
